
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import dto.Account;
import java.awt.Component;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * CustomIconRenderer class to add the suitable render for the tree .. adding the right icon to every contact
 */
class CustomIconRenderer extends DefaultTreeCellRenderer {
    
    private Icons icons;
    
    public CustomIconRenderer() {
        icons = new Icons();
    }
    public Component getTreeCellRendererComponent(JTree tree,
      Object value,boolean sel,boolean expanded,boolean leaf,
      int row,boolean hasFocus)
    {
        super.getTreeCellRendererComponent(tree, value, sel, 
          expanded, leaf, row, hasFocus);
        
        // if Node is A leaf.
        if(leaf)
        {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
            Object obj = node.getUserObject();

            if (obj instanceof Account) {
              
                Account account = (Account) obj;

                setText(account.getEmail());
                
                if (account.getStatus().equals("ONLINE")) {
                    setIcon(icons.getOnlineIcon());
                } else if(account.getStatus().equals("AWAY")) {
                    setIcon(icons.getAwayIcon());
                } else if(account.getStatus().equals("BUSY")) {
                    setIcon(icons.getBusyIcon());
                } else if (account.getStatus().equals("OFFLINE")){
                    setIcon(icons.getOfflineIcon());
                }
            }
        }
        return this;
    }
    
   
}